package com.example.mvvmtest.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;

import com.example.mvvmtest.utils.LogUtil;

public class NetworkBroadcastA extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = getResultExtras(true);
        String content = bundle.getString("next_receiver");
        LogUtil.e("NetworkBroadcastA:" + content);

        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()) {
            LogUtil.e("网络可用：" + networkInfo.isConnected());
        } else {
            LogUtil.e("网络不可用");
        }

    }
}
